﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace OrderForm
{
   public partial class MainForm : Form
   {
      public const int WM_NCLBUTTONDOWN = 0xA1;
      public const int HTCAPTION = 0x2;
      [DllImportAttribute("user32.dll")]
      public static extern bool ReleaseCapture();
      [DllImportAttribute("user32.dll")]
      public static extern int SendMessage(IntPtr hWnd, int Msg, int wParam, int lParam);

      public MainForm()
      {
         InitializeComponent();
         this.FormBorderStyle = FormBorderStyle.None;
         this.MouseDown += new MouseEventHandler(Window_MouseDown);
         SetStyle(ControlStyles.SupportsTransparentBackColor, true);
         this.BackColor = Color.WhiteSmoke;
         this.TransparencyKey = Color.WhiteSmoke;
         this.nextButton1.Visible = false;
      }

      private void Window_MouseDown(object sender, MouseEventArgs e)
      {
         if (e.Button == MouseButtons.Left)
         {
            ReleaseCapture();
            SendMessage(Handle, WM_NCLBUTTONDOWN, HTCAPTION, 0);
         }
      }

      private void boxAddress_TextChanged(object sender, EventArgs e)
      {
         UpdateButton();
         this.nextButton1.Visible = true;
      }

      private void UpdateButton()
      {
         this.nextButton1.Enabled = !string.IsNullOrWhiteSpace(this.boxName.Text) &&
                                    !string.IsNullOrWhiteSpace(this.boxAddress.Text);
      }

      // Completely exit the application
      private void buttonExit_Click_1(object sender, EventArgs e)
      {
         Application.Exit();
      }

      // Minimize window
      private void buttonMinimize_Click(object sender, EventArgs e)
      {
         WindowState = FormWindowState.Minimized;
      }

      // Official logo link
      private void OfficialWebButton_Click(object sender, EventArgs e)
      {
         System.Diagnostics.Process.Start("http://www.mcdonalds.com.tw/");
      }

      public string nameValue
      {
         get { return boxName.Text; }
      }

      private void nextButton1_Click(object sender, EventArgs e)
      {
         #region CheckTime

         TimeSpan currentTime = DateTime.Now.TimeOfDay;

         TimeSpan noonStart = new TimeSpan(11, 0, 0);
         TimeSpan noonEnd = new TimeSpan(14, 0, 0);

         TimeSpan nightStart = new TimeSpan(17, 0, 0);
         TimeSpan nightEnd = new TimeSpan(20, 0, 0);

         TimeSpan morningStart = new TimeSpan(4, 0, 0);
         TimeSpan morningEnd = new TimeSpan(10, 30, 0);

         #endregion
         
         SecondForm form2 = new SecondForm();
         form2.name = boxName.Text;
         form2.pwd = boxPhone1.Text;
         form2.address = boxAddress.Text;

         if ((currentTime > noonStart) && (currentTime < noonEnd))
         {
            form2.checkedListBox2.Enabled = true;
         }
         else if ((currentTime > nightStart) && (currentTime < nightEnd))
         {
            form2.checkedListBox2.Enabled = true;
         }
         else
         {
            form2.checkedListBox3.Enabled = true;
         }

         if ((currentTime > morningStart) && (currentTime < morningEnd))
         {
            form2.checkedListBox1.Enabled = true;
         }
         else
         {
            ;
         }
         if ((currentTime > morningStart) && (currentTime < morningEnd))
         {
            form2.checkedListBox4.Enabled = true;
         }
         else
         {
            form2.checkedListBox5.Enabled = true;
         }

         this.Hide();
         form2.Show();
      }
   }
}
